package com.gqb.threadWait;

public class Task implements Runnable {
	private Object swtich;
	private boolean flag;
	public Task(Object swtich) {
		super();
		this.swtich = swtich;
	}
	
	public void setFlag(boolean flag) {
		if(!flag){
			synchronized (swtich) {
				swtich.notifyAll();
			}
		}
		this.flag = flag;
	}

	public void wait(boolean flag) throws InterruptedException{
	}
	@Override
	public void run() {
		 synchronized (swtich) {
			 while (true) {
				 if (flag) {
						try {
							swtich.wait();
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
					 for (int i = 0; i < 100000; i++) {
//						System.out.println(i);
					}
			}
		}
	}

}
